//
//  KABExhDetGuestTCell.m
//  kabu
//
//  Created by XiangDongMBP on 2017/3/8.
//  Copyright © 2017年 East. All rights reserved.
//

#import "KABExhDetGuestTCell.h"
#import "KABModel.h"
#import <YYWebImage.h>

@implementation KABExhDetGuestTCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(coverImgViewTapped:)];
    [self.coverImgView addGestureRecognizer:tapGesture];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)coverImgViewTapped:(UIGestureRecognizer *)gesture {
    if ([self.delegate respondsToSelector:@selector(kABExhDetGuestTCell:imgViewTapped:)]) {
        [self.delegate kABExhDetGuestTCell:self imgViewTapped:(UIImageView *)gesture.view];
    }
}

- (void)configViewWithExhDetGuestItem:(KABExhDetGuestItem *)item {
    [self.coverImgView yy_setImageWithURL:[NSURL URLWithString:item.image_url] placeholder:[KABDefaultVarModel sharedInstance].bigDefaultImg];
    
    self.coverImgViewHeightConstraint.constant = 375; // 防止图片为空时，不执行completion的Block
    [self.coverImgView yy_setImageWithURL:[NSURL URLWithString:item.image_url]
                              placeholder:[KABDefaultVarModel sharedInstance].bigDefaultImg
                                  options:kNilOptions
                               completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
                                   //                                           NSLog(@"yy加载(%zd)完成BLOCK", self.index);
                                   if (image) {
                                       self.coverImgViewHeightConstraint.constant = floor([UIScreen mainScreen].bounds.size.width * image.size.height / image.size.width);
                                       [self imageViewDownLoad];
                                   }
                               }];
    
    self.nameLabel.text = item.guest_name;
}

- (void)imageViewDownLoad {
    if ([self.delegate respondsToSelector:@selector(kABExhDetGuestTCell:imgViewDownload:)]) {
        [self.delegate kABExhDetGuestTCell:self imgViewDownload:self.coverImgView];
    }
}

@end
